Skip to content

Commit

Permalink
One click revert for managers
Browse files Browse the repository at this point in the history
Ignore-this: e3c9b5f941b2f1aa83ca375861203a2f
This patch adds another button for users with the $conf['manager'] role when
viewing an old revision. It allows them to revert to this revision with a
single click.

darcs-hash:20090911081833-7ad00-5a64feb7e3e1b37178295c290a6c97c3923e82e3.gz
  • Loading branch information
splitbrain committed Sep 11, 2009
1 parent a29759c commit 1246e01
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
53 changes: 51 additions & 2 deletions inc/actions.php
Expand Up @@ -79,6 +79,15 @@ function act_dispatch(){
}
}

//revert
if($ACT == 'revert'){
if(checkSecurityToken()){
$ACT = act_revert($ACT);
}else{
$ACT = 'show';
}
}

//save
if($ACT == 'save'){
if(checkSecurityToken()){
Expand Down Expand Up @@ -185,15 +194,15 @@ function act_clean($act){

//disable all acl related commands if ACL is disabled
if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin',
'subscribe','unsubscribe','profile',
'subscribe','unsubscribe','profile','revert',
'resendpwd','subscribens','unsubscribens',))){
msg('Command unavailable: '.htmlspecialchars($act),-1);
return 'show';
}

if(!in_array($act,array('login','logout','register','save','cancel','edit','draft',
'preview','search','show','check','index','revisions',
'diff','recent','backlink','admin','subscribe',
'diff','recent','backlink','admin','subscribe','revert',
'unsubscribe','profile','resendpwd','recover','wordblock',
'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) {
msg('Command unknown: '.htmlspecialchars($act),-1);
Expand Down Expand Up @@ -225,6 +234,9 @@ function act_permcheck($act){
}
}elseif(in_array($act,array('login','search','recent','profile'))){
$permneed = AUTH_NONE;
}elseif($act == 'revert'){
$permneed = AUTH_ADMIN;
if($INFO['ismanager']) $permneed = AUTH_EDIT;
}elseif($act == 'register'){
$permneed = AUTH_NONE;
}elseif($act == 'resendpwd'){
Expand Down Expand Up @@ -319,6 +331,43 @@ function act_save($act){
return 'show';
}

/**
* Revert to a certain revision
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function act_revert($act){
global $ID;
global $REV;
global $lang;

// when no revision is given, delete current one
// FIXME this feature is not exposed in the GUI currently
$text = '';
$sum = $lang['deleted'];
if($REV){
$text = rawWiki($ID,$REV);
if(!$text) return 'show'; //something went wrong
$sum = $lang['restored'];
}

// spam check
if(checkwordblock($Text))
return 'wordblock';

saveWikiText($ID,$text,$sum,false);
msg($sum,1);

//delete any draft
act_draftdel($act);
session_write_close();

// when done, show current page
$_SERVER['REQUEST_METHOD'] = 'post'; //should force a redirect
$REV = '';
return 'show';
}

/**
* Do a redirect after receiving post data
*
Expand Down
1 change: 1 addition & 0 deletions inc/lang/en/lang.php
Expand Up @@ -49,6 +49,7 @@
$lang['btn_draft'] = 'Edit draft';
$lang['btn_recover'] = 'Recover draft';
$lang['btn_draftdel'] = 'Delete draft';
$lang['btn_revert'] = 'Restore';

$lang['loggedinas'] = 'Logged in as';
$lang['user'] = 'Username';
Expand Down
15 changes: 15 additions & 0 deletions inc/template.php
Expand Up @@ -528,6 +528,11 @@ function tpl_button($type,$return=false){
$out .= html_btn('admin',$ID,'',array('do' => 'admin'));
}
break;
case 'revert':
if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
$out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken()));
}
break;
case 'subscribe':
case 'subscription':
if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
Expand Down Expand Up @@ -692,6 +697,13 @@ function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){
'class="action admin" rel="nofollow"',1);
}
break;
case 'revert':
if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
$out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())),
$pre.(($inner)?$inner:$lang['btn_revert']).$suf,
'class="action revert" rel="nofollow"',1);
}
break;
case 'subscribe':
case 'subscription':
if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
Expand Down Expand Up @@ -1279,6 +1291,9 @@ function tpl_actiondropdown($empty='',$button='&gt;'){
}

echo '<option value="revisions">'.$lang['btn_revs'].'</option>';
if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
echo '<option value="revert">'.$lang['btn_revert'].'</option>';
}
echo '<option value="backlink">'.$lang['btn_backlink'].'</option>';
echo '</optgroup>';

Expand Down
1 change: 1 addition & 0 deletions lib/tpl/default/main.php
Expand Up @@ -113,6 +113,7 @@
<div class="bar-left" id="bar__bottomleft">
<?php tpl_button('edit')?>
<?php tpl_button('history')?>
<?php tpl_button('revert')?>
</div>
<div class="bar-right" id="bar__bottomright">
<?php tpl_button('subscribe')?>
Expand Down

0 comments on commit 1246e01

Please sign in to comment.